package top.ysez.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import top.ysez.product.entity.Product;
import top.ysez.product.service.ProductService;

import java.util.List;

/**
 * 商品实体类
 *
 * @author YsEz
 * @version V1.0.0
 * @date 2022/6/3 13:27
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

//    @Value("${server.port}")
//    private String port;

//    @Value("${spring.cloud.client.ip-address}")
//    private String ip;
  /*// 增
  @RequestMapping(value = "", method = RequestMethod.POST)
  public String saveProduct(@RequestBody Product product) {
    productService.saveProduct(product);
    return "保存成功";
  }

  // 删
  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  public void saveProduct(@PathVariable Long id) {
    productService.deleteProduct(id);
  }

  // 改
  @RequestMapping(value = "", method = RequestMethod.PUT)
  public void updateProduct(@RequestBody Product product) {
    productService.updateProduct(product);
  }*/

    /**
     * 查
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Product findById(@PathVariable Long id) {
        Product product = productService.findById(id);
//        product.setProductName("访问的服务地址:" + ip + ":" + port);
        return product;
    }

    @GetMapping("findAll")
    public List<Product> findAll() {
        List<Product> list = productService.findAll();
        System.out.println(list);
        return list;
    }
}
